Skip to content

Conversation

@justinpolygon
Copy link
Collaborator

Added futures REST and WebSocket support (alpha). Includes new REST endpoints for futures data (e.g., aggregates, contracts, market statuses, etc) and WebSocket event parsing (e.g. trades, quotes, and aggregates).

REST examples:

from polygon import RESTClient

client = RESTClient(trace=True)

# Retrieve aggregate data (e.g., OHLC) for a specific futures contract
# URL Path: /futures/vX/aggs/{ticker}
futures = client.list_futures_aggs(ticker="ESZ4", resolution="1Min", limit=10)
for agg in futures:
    print(agg.ticker, agg.open, agg.close)

# Retrieve a list of all available futures contracts
# URL Path: /futures/vX/contracts
contracts = client.list_futures_contracts()
for contract in contracts:
    print(contract)

# Retrieve details for a specific futures contract using its ticker
# URL Path: /futures/vX/contracts/{ticker}
contract = client.get_futures_contract(ticker="00CJ5")
print(contract)

# Retrieve a list of all futures products
# URL Path: /futures/vX/products
for product in client.list_futures_products():
    print(product)

# Retrieve details for a specific futures product using its product code
# URL Path: /futures/vX/products/{product_code}
product = client.get_futures_product(product_code="EBE")
print(product)

# Retrieve trading schedules for futures by session start date
# URL Path: /futures/vX/schedules
for schedule in client.list_futures_schedules_by_session_start_date():
    print(schedule)

# Retrieve trading schedules for a specific futures product using its product code
# URL Path: /futures/vX/products/{product_code}/schedules
for schedule in client.list_futures_product_schedules(product_code="ES"):
    print(schedule)

# Retrieve a list of trades for a specific futures contract
# URL Path: /futures/vX/trades/{ticker}
for trade in client.list_futures_trades(ticker="ESZ4", limit=10):
    print(trade)

# Retrieve a list of quotes for a specific futures contract
# URL Path: /futures/vX/quotes/{ticker}
for quote in client.list_futures_quotes(ticker="ESZ5", limit=10):
    print(quote)

# Retrieve and print all futures market statuses
# URL Path: /futures/vX/quotes/{ticker}
for status in client.list_futures_market_statuses():
    print(status)

Websocket examples:

from polygon import WebSocketClient
from polygon.websocket.models import WebSocketMessage, Feed, Market
from typing import List

client = WebSocketClient(
	api_key="XXXX",
	feed=Feed.RealTime,
	market=Market.Futures,
	verbose=True
	)

# trades, quotes, aggs min/sec
client.subscribe("T.*")
client.subscribe("Q.*")
client.subscribe("A.*")
client.subscribe("AM.*")

def handle_msg(msgs: List[WebSocketMessage]):
    for m in msgs:
        print(m)

# print messages
client.run(handle_msg)

This is a work in progress PR and will get updates as things evolve.

@justinpolygon
Copy link
Collaborator Author

Closing for latest sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants